package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private  Student[] stus = new Student[5];

    public  boolean addStudent(Student stu) {
        int index = -1;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null) {
                index = i;
                break;
            }
        }
        //判断index是否变化，从而看数组是否满了
        if (index == -1) {
            return false;
        } else {
            stus[index] = stu;
            return true;
        }
    }


    public Student[] find() {
        return stus;
    }

    public boolean remove(String id) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i]!=null&&id.equals(stus[i].getID())){
                stus[i]=null;
                return true;
            }
        }
        return false;
    }

    public boolean change(String id, String name, String age, String birth) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i]!=null&&id.equals(stus[i].getID())){
                stus[i].setName(name);
                stus[i].setAge(age);
                stus[i].setBirthday(birth);
                return true;
            }
        }
        return false;
    }
}
